/*
 * $RCSfile: RoomThread.java,v $
 * $Revision: 1.1  $
 * $Date: 2012-8-14  $
 *
 * Copyright (C) 2005 Bettem, Inc. All rights reserved.
 *
 * This software is the proprietary information of Bettem, Inc.
 * Use is subject to license terms.
 */
package com.dzpk.gameserver.module.main;
/*
 * $RCSfile: RoomThread.java,v $
 * $Revision: 1.1  $
 * $Date: 2012-8-14  $
 *
 * Copyright (C) 2005 Bettem, Inc. All rights reserved.
 *
 * This software is the proprietary information of Bettem, Inc.
 * Use is subject to license terms.
 */

import com.dzpk.gameserver.module.main.room.Room;
import org.apache.log4j.Logger;


/**
 * 房间线程
 */
public class RoomThread {
    private Logger logger = Logger.getLogger(RoomThread.class);
    private Thread thread;
    private RoomCourse roomCourse;
    private long threadId;
    private long onlineTime = System.currentTimeMillis();
    private int close; //0 正常 -1关闭
    private Room room;

    public Long getThreadId() {
        return threadId;
    }

    public Room getRoom() {
        return room;
    }

    public RoomThread(Room room) {
        logger.debug("start roomThread :" + room.getRoomId());
        this.room = room;
        this.threadId = room.getRoomId();
        roomCourse = new RoomCourse(room);
        roomCourse.setRoomThread(this);
        thread = new Thread(roomCourse, String.valueOf(this.threadId));
        thread.start();
        Cache.addRoom(room);
        logger.debug("start roomThread ok......");
    }

    public void close(long id) {
        logger.debug("......RoomThread close roomThread :" + id);
        this.close = -1;
        roomCourse.close();
        try {
            thread.interrupt();
            Cache.deleteRoom(id);
            logger.debug("RoomThread close roomThread OK....");
        } catch (Exception e) {
            logger.error(".......RoomThread close RoomThread err id" + id, e);
        }
    }

    public RoomCourse getRoomCourse() {
        return roomCourse;
    }

    public long getOnlineTime() {
        return onlineTime;
    }

    public void setOnlineTime(long onlineTime) {
        this.onlineTime = onlineTime;
    }

    public int getClose() {
        return close;
    }

    public void setClose(int close) {
        this.close = close;
    }

}

